#include "Pch.h"

#include "TestCase.h"


void CommitRateTest::DoRun()
{
    const IniSection* common = m_iniFile.GetSection( L"Common" );
    const Uint numThreads = common->GetUintValue( L"NumThreads" );

    const IniSection* build = this->GetBuildSection();
    const Uint numWorks = build->GetUintValue( L"NumWorks" );

    const Uint totalCommits = numThreads * numWorks;

    cout << "Num threads : " << numThreads << endl
         << "Num works/T : " << numWorks << endl
         << "Total commits : " << totalCommits << endl
         << endl;

    TickClock clock;

    for ( Uint i = 0; i < numThreads; ++ i )
    {
        m_threads.AddOnceThread( "Execute", boost::bind( &CommitRateTest::Execute, this, numWorks ));
    }

    while ( 0 < m_threads.GetNumAliveThreads() )
    {
        ThisThread::Sleep( 1 );
    }

    const Uint elapsed = clock.Delta();

    cout << "Elapsed : " << elapsed << endl
         << "Commits per second : " << totalCommits / ( static_cast< Float >( elapsed ) / 1000.f ) << endl;


    while ( 0 < m_executor->GetNumWorks() )
    {
        ThisThread::Sleep( 1 );
    }
}


void CommitRateTest::Execute( Uint numWorks )
{
    for ( Uint i = 0; i < numWorks; ++ i )
    {
        m_executor->SubmitWork(
            "Perform", boost::bind( &CommitRateTest::Perform, this ));
    }
}


void CommitRateTest::Perform()
{
}
